package com.xinziruo.richclient.util;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;

/**
 * 
 * @author loudyn
 *
 */
public class AppUtils {

	/**
	 * 
	 * @param component
	 */
	public static Component alignCenter(Component component) {

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		
		Dimension componentSize = component.getSize();
		if (componentSize.height > screenSize.height) {
			componentSize.height = screenSize.height;
		}
		
		if (componentSize.width > screenSize.width) {
			componentSize.width = screenSize.width;
		}
		
		component.setLocation(
								(screenSize.width - componentSize.width) / 2,
								(screenSize.height - componentSize.height) / 2
						);
		
		return component;
	}
}
